<?php

/**
 * @author 
 * @copyright 2008
 */
$categories = array(
'azart'=>'Азартные флеш игры',
'arcade'=>'Флеш аркады',
'classic'=>'Классические флеш игры',
'table'=>'"Настольные" флеш игры',
'strategy'=>'Флеш стратегии',
'shooter'=>'Флеш стрелялки',
'quest'=>'Флеш квесты',
'race'=>'Флеш гонки',
'fight'=>'Флеш драки',
'other'=>'Оригинальные флеш игры',
'children'=>'Детские флеш игры',
'sport'=>'Спортивные флеш игры',
'logic'=>'Логические флеш игры'
);
$obj = new FlashGameWizard($db);
$table_ratings = $db->pfx."ratings";
$show="index";
$from = 0;
$per_page = 20;
if(isset($_REQUEST['from']) and intval($_REQUEST['from']) != 0)
{
	$from = intval($_REQUEST['from']);
}
$lim_from = $from * $per_page;
/** Остаток пути. который используется в качестве списка входных данных **/
$over = $this->fetchPath($this->path);
if(!empty($over))
{
	if(preg_match("/^cat_(\w+)$/",strval($over[0]),$searched_category))
	{
		$cat_alias = $searched_category[1];
		$selected_cat = $obj->cat->db->fetch_one("SELECT * FROM ".$obj->cat->table." WHERE alias = '".mysql_real_escape_string($cat_alias)."' AND status = '2'");
		if($selected_cat != false)
		{
			$selected_cat_id = $selected_cat['id'];
			$show = "category";
		}
		else error404();
	}
	elseif(preg_match("/^(\w+).html$/",strval($over[0]),$searched_item))
	{
		$item_alias = $searched_item[1];
		$selected_item = $obj->db->fetch_one("SELECT * FROM $obj->table WHERE alias = '".mysql_real_escape_string($item_alias)."' AND status = '2'");
		if($selected_item != false)
		{
			$selected_cat_id = $selected_item['category_id'];
			$item_id = $selected_item['id'];
			$show = "item";
		}
		else error404();
	}
}
//TODO: Категории игр
//print_var($main_cat);
if($obj->flash_main_cat != false)
{
	$cats = $obj->cat->getChilds($obj->flash_main_cat['id'],2);
	//print_var($cats);
	if(!empty($cats))
	{
		$smarty->assign("cats",$cats);
		$blocks['left'][] = array("content" => $smarty->fetch("modules/$this->dir/templates/cats.inc.html"));
	}
}
//TODO: Топ5 игр сайта
$top10limit = 5;
$top10dir = "flash";
$top10list = $db->fetch_list("
SELECT 
	g.id 
FROM $obj->table AS g,".$obj->cat->table." AS c 
WHERE 
	g.status = '2' AND g.file = '1' AND g.image = '1' AND c.id = g.category_id AND c.status = '2' 
ORDER BY g.rating DESC, g.votes DESC, g.hits DESC, g.time DESC 
LIMIT $top10limit");
if(!empty($top10list))
{
	$top10 = $obj->getFullInfoByList($top10list);
	$smarty->assign("top10",$top10);
	$blocks['right'][] = array("content" => $smarty->fetch("modules/$this->dir/templates/top10.inc.html"));
}
//TODO: Три последних игры
$last3limit = 3;
$last_dir = "flash";
$last_games_list = $db->fetch_list("SELECT g.$obj->id FROM $obj->table AS g,".$obj->cat->table." AS c WHERE g.status = '2' AND c.id = g.category_id ORDER BY g.time DESC LIMIT $last3limit");
if($last_games_list != false)
{
	$last_games = $obj->getFullInfoByList($last_games_list);
	$smarty->assign("last_games",$last_games);
	$blocks['left'][] = array("content" => $smarty->fetch("modules/$this->dir/templates/last_games.inc.html"));
}
if($show == "index")
{
	include("index.action.php");
}
elseif($show == "category")
{
	include("category.action.php");
}
elseif($show == "item")
{
	include("item.action.php");
}
//print_var($blocks);
if(isset($blocks)){$smarty->assign("blocks",$blocks);}
if(isset($action_template)){$smarty->assign("action_template","modules/".$this->dir.TMPL_DIR.$action_template.".action.html");}
if(isset($_SESSION['message']))
{
	$smarty->assign("system_message",$_SESSION['message']);
	unset($_SESSION['message']);
}
?>